import top.malaoshi.data.DataColumn;
import top.malaoshi.data.DataRow;
import top.malaoshi.data.DataTable;
import top.malaoshi.data.GroupBy;
import top.malaoshi.util.Out;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class StdGroupBy多列相同值 {

    public static void main1(String[] args) {

        List<Integer> list = new ArrayList<>();
        Collections.addAll(list,1,2,3,4,1,1,2,2,2,2,3);


        Map<Integer, List<Integer>> map = list.stream()
                .collect(Collectors.groupingBy(e -> e));

        System.out.println(map);

    }

    static DataTable createTable(){
        DataTable dt = new DataTable("t_user");

        dt.columns().add("id");
        dt.columns().add("username", DataColumn.Type.TEXT);
        dt.columns().add("password", DataColumn.Type.TEXT);
        dt.columns().add("age", DataColumn.Type.INT);
        dt.columns().add("height", DataColumn.Type.DOUBLE);
        dt.columns().add("sex", DataColumn.Type.TEXT);


        dt.rows().add(new Object[]{1,"lilei","123456",20,1.83,"男"});
        DataRow drHmm = dt.rows().add(new Object[]{2, "韩梅梅", "666", 20,1.65,"女"});


        dt.rows().add(new Object[]{5,"张三","123456",20,1.83});
        dt.rows().add(new Object[]{6,"李四","123456",30,1.83,"男"});
        dt.rows().add(new Object[]{7,"杜子腾","123456",30,1.83,"男"});
        dt.rows().add(new Object[]{8,"史珍香","123456",20,1.68,"女"});
        dt.rows().add(new Object[]{9,"王五","123456",20,1.83,"男"});
        dt.rows().add(new Object[]{10,"乔峰","123456",20,1.83,"男"});
        dt.rows().add(new Object[]{11,"段誉","123456",30,1.83,"男"});
        dt.rows().add(new Object[]{11,"小龙女","123456",30,1.83,"女"});
        dt.rows().add(new Object[]{11,"王语嫣","123456",30,1.83,"女"});

        return dt;
    }

    public static void main(String[] args) {

        DataTable dt = createTable();

//        List<GroupBy.Result>  list = dt.groupBy("age");
        List<GroupBy.Result>  list = dt.groupBy("age","sex").getResult();

        for(GroupBy.Result result : list){
            List<Object> columns = result.getColumns();
            List<DataRow> dataRows = result.getDataRows();

            Out.println("columns:",columns);
            Out.println("dataRows:",dataRows);
        }


    }
}
